/*
 * @Author: chunlai
 * @Date: 2025-04-10 08:23:49
 * @LastEditTime: 2025-09-02 10:11:17
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\router\index.js
 * @Description:
 */

import Vue from "vue";
import Router from "vue-router";
import store from "../store/index";
import routes from "./routes";

Vue.use(Router);

// 解决:Avoided redundant navigation to current location: “/XXX“.路由重复问题
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((error) => error);
};

const router = new Router({
  routes: [
    {
      path: "/",
      redirect: "/index",
    },
    {
      path: "/index",
      name: "Index",
      component: routes.index,
      meta: {
        title: "", // 缓存首页
        keepAlive: true,
      },
    },
    {
      path: "/transcribe",
      name: "TranscribePage",
      component: routes.transcribe,
      meta: {
        title: "风险提示",
      },
    },
    {
      path: "/presure",
      name: "PreSurePage",
      component: routes.presure,
      meta: {
        title: "投保须知",
      },
    },
    {
      path: "/colligate",
      name: "ColligateClausePage",
      component: routes.colligate,
      meta: {
        title: "投保条款",
        keepAlive: true,
      },
    },
    {
      path: "/count",
      name: "CountIndex",
      component: routes.count,
      meta: {
        title: "保费试算",
        keepAlive: false,
      },
    },
    {
      path: "/form",
      name: "InfoForm",
      component: routes.form,
      meta: {
        title: "投保页面",
        keepAlive: false,
      },
    },
    {
      path: "/prenotice",
      name: "PreNoticeIndex",
      component: routes.prenotice,
      meta: {
        type: "change",
        title: "告知问卷",
      },
    },
    {
      path: "/nethealthy",
      name: "NetSimpleHealthy",
      component: routes.nethealthy,
      meta: {
        type: "change",
        title: "投保告知",
      },
    },
    {
      path: "/healthy",
      name: "HealthyIndex",
      component: routes.healthy,
      meta: {
        type: "change",
        title: "告知问卷",
      },
    },
    // 投/被保人
    {
      path: "/notify",
      name: "Step3Detail",
      component: routes.notify,
      meta: {
        type: "change",
        title: "告知详情",
      },
    },
    {
      path: "/agentnotify",
      name: "AgentNotice",
      component: routes.agentnotify,
      meta: {
        type: "change",
        title: "代理人告知",
      },
    },
    {
      path: "/cq_notify",
      name: "ChongQingNotice",
      component:routes.cqnotify,
      meta: {
        type: "change",
        title: "重庆告知",
      },
    },
    {
      path: "/recall_notify",
      name: "RecallNotice",
      component: routes.recallnotify,
      meta: {
        type: "change",
        title: "销售人员告知书",
      },
    },

    {
      path: "/simple_notify",
      name: "SimpleNotice",
      component: routes.simplenotify,
      meta: {
        type: "change",
        title: "简易告知",
      },
    },
    {
      path: "/files",
      name: "files",
      meta: {
        title: "影像件资料",
      },
      component: routes.files,
    },
    {
      // 订单详情
      path: "/billsure",
      name: "billSurePage",
      component: routes.billsure,
      meta: {
        title: "订单确认页",
      },
    },
    // 文件阅读
    {
      path: "/read",
      name: "ReadPage",
      component: routes.read,
      meta: {
        title: "条款详情",
      },
    },
    {
      path: "/preinsure",
      name: "PreInsurePage",
      component:routes.preinsure,
      meta: {
        title: "",
      },
    },
    {
      path: "/pay",
      name: "PaymentPage",
      component: routes.pay,
      meta: {
        title: "支付确认",
      },
    },
    {
      path: "/associate",
      name: "OrderAssociation",
      component: routes.associate,
      meta: {
        title: "万能险订单关联",
      },
    },
    {
      path: "/qnaire",
      name: "OmnipQuestionaire",
      component: routes.qnaire,
      meta: {
        title: "万能问卷",
      },
    },
    {
      path: "/risknair",
      name: "OmnipQuestioRes",
      component: routes.risknair,
      meta: {
        title: "客户问卷",
      },
    },

    /* ===== 最新投保页(2023-7-25) ===== */
    {
      path: "/newsign",
      name: "SignBeforeSurePage",
      component: routes.newsign,
      meta: {
        title: "授权与须知签名",
      },
    },
    {
      path: "/replace",
      name: "BankcardReplacePage",
      component: routes.replace,
      meta: {
        title: "更换银行卡",
      },
    },
    {
      path: "/contract",
      name: "BankcardContractPage",
      component: routes.contract,
      meta: {
        title: "签约",
      },
    },
    {
      path: "/shareres",
      name: "ShareResultPage",
      meta: {
        title: "结果页",
      },
      component:routes.shareres,
    },
    {
      path: "/billres",
      name: "BillResultPage",
      meta: {
        title: "投保结果",
      },
      component: routes.billres,
    },
    {
      path: "/netnair",
      name: "NetNairPage",
      meta: {
        title: "互联网适当性评估问卷",
      },
      component: routes.netnaire,
    },
    {
      path: "*",
      component: () => import("@/components/NotFound"),
    },
  ],
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部，除非指定了 savedPosition
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
});
router.beforeEach((to, from, next) => {
  let { title } = to.meta;
  document.title = title || store.state.varietyInfo.productName;
  next();
});

export default router;
